package cz.czu.pef.DataModelling;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.SequenceGenerator;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@Scope(value="prototype")
@Transactional
@Embeddable
@MappedSuperclass
public abstract class IdPersistenceObject implements Serializable
{
	private static final long serialVersionUID = -8510497330398319921L;

	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="generatorName")
	@SequenceGenerator(name="generatorName", sequenceName="HibernateIdGenSeq", allocationSize=1)
	@Column(name="id")
	private long id;
	
	protected IdPersistenceObject()
	{
	}

	public long getId()
	{
		return id;
	}
	
	public void setId(long id)
	{
		this.id = id;
	}

	@Override
	public String toString()
	{
		StringBuilder builder = new StringBuilder();
		builder.append("IdPersistenceObject [id=");
		builder.append(id);
		builder.append("]");
		return builder.toString();
	}

	public abstract boolean canBeRemoved();
}
